#ifndef CLIENT_VISTA_ACESSACCOUNT_H_
#define CLIENT_VISTA_ACESSACCOUNT_H_
#include <iostream>
#include <gtkmm.h>
#include <fstream>

class AccessAccount: public Gtk::Window{

public:
    AccessAccount():accept_button("Accept"), cancel_button("Cancel"),user_label("User: "),
                      pass_label("Password: "),restriction_label_user ("[Max 12 chars]"),
                      restriction_label_pass("[Max 12 chars]"), m_check("Remember account"),box(true,0){
    	set_size_request(400, 400);
    	set_title("Access Account");
    	set_border_width(10);
    	remember = false; // No recordar user+password

    	//Asociacion de funciones que se deben llamar ante el evento de pulsado de un boton
    	accept_button.signal_clicked().connect(
				sigc::mem_fun(*this, &AccessAccount::accept_clicked));
		cancel_button.signal_clicked().connect(
				sigc::mem_fun(*this, &AccessAccount::cancel_clicked));

		//limitaciones para los campos
		user_entry.set_max_length(12);
		pass_entry.set_max_length(12);
		pass_entry.property_visibility()=false;

		cancel = false;
		add(box);

		hbox_user.pack_start(user_label);
		hbox_user.pack_start(user_entry);
		hbox_user.pack_start(restriction_label_user);
		box.pack_start(hbox_user);

		hbox_pass.pack_start(pass_label);
		hbox_pass.pack_start(pass_entry);
		hbox_pass.pack_start(restriction_label_pass);
		box.pack_start(hbox_pass);
		box.pack_start(m_check);

		hbox_option.pack_start(accept_button);
		hbox_option.pack_start(cancel_button);
		box.pack_start(hbox_option);
		show_all_children();




    }

    std::string getUser(){
    	return user;
    }
    std::string getPass(){
    	return pass;
    }

    bool is_remember_account(){
    	return remember;
    }
    ~AccessAccount(){}

bool is_cancel(){
	return cancel;
}

bool dont_exists_configuration(){
	std::ifstream cfg("cfg.properties",std::ifstream::in);
	return (not cfg.is_open());
}
protected:
    void accept_clicked(){
    	if(user_entry.get_text() == ""){
    		Gtk::MessageDialog dialog(*this,"Debe ingresar un usuario");
    		dialog.run();

    	}
    	else if(pass_entry.get_text()==""){
    		Gtk::MessageDialog dialog(*this,"Debe ingresar un password");
    		dialog.run();
    	}
    	else if(dont_exists_configuration()){
    		Gtk::MessageDialog dialog(*this,"No hay una configuracion realizada. Por favor, vuelva a la pantalla principal e ingrese a 'Configuration'");
    		dialog.run();
    	}
    	else{
    	    if (m_check.get_active()){
    		    remember =true;
    	    }
    	    user = user_entry.get_text();
    	    pass = pass_entry.get_text();
    	    hide();
    	}

    }

    void cancel_clicked(){
    	cancel=true;
    	hide();
    }


private:
    bool cancel;
    Gtk::VBox box;
    Gtk::HBox hbox_user,hbox_pass,hbox_option;
    Gtk::Button accept_button,cancel_button;
    Gtk::CheckButton m_check;
    Gtk::Label user_label, pass_label, restriction_label_user,restriction_label_pass;
    Gtk::Entry user_entry, pass_entry;
    bool remember;
    std::string user, pass;
};
#endif /* CLIENT_VISTA_ACESSACCOUNT_H_ */
